package shuashuami.hb.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.glid.GlidUtil;
import shuashuami.hb.com.model.Csubordinate;
import shuashuami.hb.com.view.CTIjiaoShenqingDialog;

/**
 * Created by Administrator on 2017/6/20.
 */

public class CSubordinateAdatper extends BaseAdapter {
    private LayoutInflater inflater;
    private List<Csubordinate> list;
    private Context con;
    private GlidUtil glidUtil;

    public CSubordinateAdatper(List<Csubordinate> list, Context context) {
        this.con = context;
        inflater = LayoutInflater.from(context);
        this.list = list;
        glidUtil = new GlidUtil(context);
    }

    @Override
    public int getCount() {
        if (null != list) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CSubordinateViewHoler viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_csubordinate_layout, null);
            viewHolder = new CSubordinateViewHoler();
            viewHolder.imgHead = (ImageView) convertView.findViewById(R.id.img_csubordinate_head_image);
            viewHolder.tvNickanme = (TextView) convertView.findViewById(R.id.tv_csubordinate_nick_name);
            viewHolder.tvID = (TextView) convertView.findViewById(R.id.tv_csubordinate_id_phone_num);
            viewHolder.tvState = (TextView) convertView.findViewById(R.id.tv_csubordinate_state);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (CSubordinateViewHoler) convertView.getTag();
        }
        final Csubordinate content = list.get(position);
        glidUtil.uploadCircle(content.getHeadImage(), viewHolder.imgHead, R.mipmap.ssm_icon_11);
        viewHolder.tvNickanme.setText(content.getNickName());
        viewHolder.tvID.setText("ID：" + content.getId() + " " + content.getPhoneNum());
        if (content.getState() == 2) {
            viewHolder.tvState.setText("审核通过");
            viewHolder.tvState.setTextSize(12);
            viewHolder.tvState.setTextColor(0xff4c8bfe);
            viewHolder.tvState.setPadding(0, 0, 0, 0);
            viewHolder.tvState.setBackgroundResource(0);
        } else if (content.getState() == 1) {
            viewHolder.tvState.setText("等待审核");
            viewHolder.tvState.setTextColor(0xff4c8bfe);
            viewHolder.tvState.setPadding(30, 10, 30, 10);
            viewHolder.tvState.setTextSize(10);
            viewHolder.tvState.setBackgroundResource(0);
            //   viewHolder.tvState.setBackgroundResource(R.drawable.shape_corner_csubordinate_submit_tv_bg);
        } else if (content.getState() == 3) {
            viewHolder.tvState.setText("冻结");
            viewHolder.tvState.setTextColor(0xffff0000);
            viewHolder.tvState.setPadding(30, 10, 30, 10);
            viewHolder.tvState.setTextSize(10);
            viewHolder.tvState.setBackgroundResource(0);
            //    viewHolder.tvState.setBackgroundResource(R.drawable.shape_corner_csubordinate_submit_tv_bg);
        } else {
            viewHolder.tvState.setText("提交审核");
            viewHolder.tvState.setTextColor(0xffffffff);
            viewHolder.tvState.setPadding(30, 10, 30, 10);
            viewHolder.tvState.setTextSize(10);
            viewHolder.tvState.setBackgroundResource(R.drawable.shape_corner_csubordinate_submit_tv_bg);
            viewHolder.tvState.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CTIjiaoShenqingDialog ctIjiaoShenqingDialog = new CTIjiaoShenqingDialog(con, content.getId() + "");
                    ctIjiaoShenqingDialog.show();
                }
            });
        }

        return convertView;
    }

    class CSubordinateViewHoler {
        public ImageView imgHead;
        public TextView tvNickanme;
        public TextView tvID;
        public TextView tvState;
    }


}




